package com.qiyu.jvm.tlab;

/**
 * 启动参数：-server -Xmx15m -Xms15m -XX:+DoEscapeAnalysis -XX:+PrintGC -XX:-UseTLAB -XX:+EliminateAllocations
 *
 * 关闭逃逸分析：     481541       11556984  com.qiyu.jvm.tlab.User
 * 开启逃逸分析：     513257       12318168  com.qiyu.jvm.tlab.User
 * @Author linhao
 * @Date created in 3:59 下午 2021/1/4
 */
public class AllocInStack {

    public  User alloc(int id, String name) {
        User user = new User();
        user.setId(id);
        user.setUsername(name);
        return user;
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        AllocInStack allocInStack = new AllocInStack();
        for (int i = 0; i < 1000000; i++) {
            User user = allocInStack.alloc(i, "idea-" + i);
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);
        while (true){

        }
    }
}
